from typing import List


class Solution:
    def candy(self, ratings: List[int]) -> int:
        if not ratings:
            return 0

        arr = [1] * len(ratings)
        for i in range(1, len(ratings)):
            if ratings[i] > ratings[i - 1]:
                arr[i] = arr[i - 1] + 1
        print(arr)
        for i in range(len(ratings) - 1, 0, -1):
            if ratings[i] < ratings[i - 1]:
                arr[i - 1] = max(arr[i] + 1, arr[i - 1])
        print(arr)
        return sum(arr)


if __name__ == "__main__":
    res = Solution().candy([1, 3, 4, 5, 2])
    print(res)
